home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / stdev.pro < prev    next >
Text File  |  1997-07-08  |  1KB  |  58 lines

  1. ; $Id: stdev.pro,v 1.2 1997/01/15 04:02:19 ali Exp $
  2. ;
  3. ; Copyright (c) 1983-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. Function STDEV, Array, Mean
  7. ;
  8. ;+
  9. ; NAME:
  10. ;    STDEV
  11. ;
  12. ; PURPOSE:
  13. ;    Compute the standard deviation and, optionally, the
  14. ;    mean of any array.
  15. ;
  16. ; CATEGORY:
  17. ;    G1- Simple calculations on statistical data.
  18. ;
  19. ; CALLING SEQUENCE:
  20. ;    Result = STDEV(Array [, Mean])
  21. ;
  22. ; INPUTS:
  23. ;    Array:    The data array.  Array may be any type except string.
  24. ;
  25. ; OUTPUTS:
  26. ;    STDEV returns the standard deviation (sample variance
  27. ;    because the divisor is N-1) of Array.
  28. ;        
  29. ; OPTIONAL OUTPUT PARAMETERS:
  30. ;    Mean:    Upon return, this parameter contains the mean of the values
  31. ;        in the data array.
  32. ;
  33. ; COMMON BLOCKS:
  34. ;    None.
  35. ;
  36. ; SIDE EFFECTS:
  37. ;    None.
  38. ;
  39. ; RESTRICTIONS:
  40. ;    None.
  41. ;
  42. ; PROCEDURE:
  43. ;    Mean = TOTAL(Array)/N_ELEMENTS(Array)
  44. ;    Stdev = SQRT(TOTAL((Array-Mean)^2/(N-1)))
  45. ;
  46. ; MODIFICATION HISTORY:
  47. ;    DMS, RSI, Sept. 1983.
  48. ;-
  49.     on_error,2        ;return to caller if error
  50.     n = n_elements(array)    ;# of points.
  51.     if n le 1 then message, 'Number of data points must be > 1'
  52. ;
  53.         mean = total(array)/n    ;yes.
  54.         return,sqrt(total((array-mean)^2)/(n-1))
  55.  
  56.        end
  57.  
  58.